package cn.iocoder.yudao.module.engine.model.aichat;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;

public class AIChatFuture {
    private final String chatId;
    private String userText;
    private Future<?> llmFuture;
    private final List<Future<?>> ttsFutures = Collections.synchronizedList(new ArrayList<>());
    private boolean cancelled = false;

    public AIChatFuture(String chatId, String userText) {
        this.chatId = chatId;
        this.userText = userText;
    }

    public String getChatId() {
        return chatId;
    }

    public String getUserText() {
        return userText;
    }

    public void setUserText(String userText) {
        this.userText = userText;
    }

    public Future<?> getLlmFuture() {
        return llmFuture;
    }

    public void setLlmFuture(Future<?> llmFuture) {
        this.llmFuture = llmFuture;
    }

    public int getTtsFuturesSize() {
        return ttsFutures.size();
    }

    public void removeTtsFuture(Future<?> future) {
        ttsFutures.remove(future);
    }

    public void addTtsFuture(Future<?> future) {
        ttsFutures.add(future);
    }

    public List<Future<?>> getTtsFuturesWithCopy() {
        if (ttsFutures == null) {
            return null;
        }
        return new ArrayList<>(ttsFutures);
    }

    public void clearTtsFutures() {
        if (ttsFutures != null) {
            ttsFutures.clear();
        }
    }

    public boolean isCancelled() {
        return cancelled;
    }

    public void setCancelled(boolean cancelled) {
        this.cancelled = cancelled;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("AIChatFuture{");
        sb.append("chatId='").append(chatId).append('\'');
        sb.append(", textFromUser='").append(userText).append('\'');
        sb.append(", llmFuture=").append(llmFuture);
        sb.append(", ttsFutures=").append(ttsFutures);
        sb.append(", cancelled=").append(cancelled);
        sb.append('}');
        return sb.toString();
    }
}
